<?php
include_once( "include/global.php" );
include_once( "include/process_db.php" );

header('Cache-Control: no-cache, must-revalidate');
header('Content-type: application/json');

// the data array to return
$ret = array();
$ret["status"] = "success";
$ret["error_msg"] = "";

// open database
OpenDB();

// return user id
$ret["user_id"] = $_SESSION["user_id"];

// get user list
$ret["user_list"] = QueryRecordData( "users" );

// get fields
$ret["field_list"] = QueryRecordData( "fields" );

// get the oldest year
$smallest_year = QueryRecordData( "main", "1 ORDER BY Date ASC LIMIT 1", "YEAR(Date) as SMALLEST_YEAR" );
$ret["smallest_year"] = $smallest_year[0]["SMALLEST_YEAR"];

// close database
CloseDB();

// return data
echo json_encode( $ret );
?>
